import 'package:flutter/material.dart';

/// description: 全局隐藏键盘,点击空白处隐藏键盘,点击输入框显示键盘
class HideKeyboard extends StatelessWidget {
  const HideKeyboard({
    required this.child,
    super.key,
  });

  final Widget child;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: child,
      onTap: () {
        final FocusScopeNode currentFocus = FocusScope.of(context);
        if (!currentFocus.hasPrimaryFocus &&
            currentFocus.focusedChild != null) {
          FocusManager.instance.primaryFocus?.unfocus();
        }
      },
    );
  }
}
